﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Winter.BackEnd.Models.Domain;

namespace Winter.BackEnd
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                null,
                "",
                new { controller = "Home", action = "Index" }
            );
            routes.MapRoute(
                null,
                "Person",
                new { controller = "Person", action = "Index" }
            );
            routes.MapRoute(
                null,
                "Person/UserInfo/{id}",
                new { controller = "Person", action = "UserInfo" },
                new { id = @"\d+" }
            );
            routes.MapRoute(
                null,
                "Person/Info/{id}",
                new { controller = "Person", action = "GetPersonInfo" },
                new { id = @"\d+" }
            );
            routes.MapRoute(
               null,
               "Person/GetDashbordInfo",
               new { controller = "Person", action = "GetDashbordInfo" }
           );
            routes.MapRoute(
               null,
               "Class/Details/{id}",
               new { controller = "Classes", action = "Details" },
               new { id = @"\d+" }
           );
            routes.MapRoute(
              null,
              "Classes/Map/{buildingName}",
              new { controller = "Classes", action = "Map" },
              new { buildingName = @".+" }
          );
            routes.MapRoute(
                null,
                "404",
                new { controller = "Error", action = "PageNotFound" }
                );
            routes.MapRoute(
               "Jquery",
               "Group/GetShortSubjectDetails/{Id}",
               new { controller = "Group", action = "GetShortSubjectDetails" });

            routes.MapRoute(
               "JqueryGroup",
               "Group/GetScheduleForGroup/{Id}",
               new { controller = "Group", action = "GetScheduleForGroup" });

            routes.MapRoute(
             "JqueryGroupSaves",
             "Group/SaveEvent/{json}",
             new { controller = "Group", action = "SaveClass" }
             );
            routes.MapRoute(
             "SaveEvents",
             "Group/SaveEvent/{end_date}/{end_time}/{start_date}/{start_time}/{text}/{id}/{event_legth}/{rec_type}",
             new { controller = "Group", action = "SaveEvent" });

            routes.MapRoute(
              "JqueryUniversities",
              "Universities/GetItemDetails/{CategoryName}/{Id}",
              new { controller = "Universities", action = "GetItemDetails" });

            routes.MapRoute(
             "JqueryUniversitiesStudents",
             "Universities/GetStudetnsForItem/{CategoryName}/{Id}",
             new { controller = "Universities", action = "GetStudetnsForItem" });

            routes.MapRoute(
                null,
                "Message/{messageId}",
                new { controller = "Message", action = "ViewMessage" },
                new { messageId = @"\d+" }
            );
            routes.MapRoute(
                null,
                "Message/DeleteMessage/{messageId}",
                new { controller = "Message", action = "DeleteMessage" },
                new { messageId = @"\d+" }
            );
            routes.MapRoute(
               null,
               "Message/SendMessage/{messageSubject}/{messageBody}/{recipientName}",
               new { controller = "Message", action = "SendMessage" }
           );
            routes.MapRoute(
              null,
              "Message/Send/{recepientID}",
              new { controller = "Message", action = "Index" }
          );
            routes.MapRoute(
               null,
               "Subjects/GetScheduleHourPerWeek/{subjectType}",
               new { controller = "Subjects", action = "GetScheduleHourPerWeek" }
           );
            routes.MapRoute(
              null,
              "Subjects/GetScheduleLectureClasses/{subjectType}",
              new { controller = "Subjects", action = "GetScheduleLectureClasses" }
          );
           routes.MapRoute(
              null,
              "Subjects/GetScheduleExams/{subjectType}",
              new { controller = "Subjects", action = "GetScheduleExams" }
          );
           routes.MapRoute(
             null,
             "Person/AddFriend/{userID}",
             new { controller = "Person", action = "AddFriend" }
         );
            routes.MapRoute(
                null,
                "{controller}/{action}",
                new { controller = "", action = "Index" }
            );
        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            Repository.UpdateCurrentDataContext();
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("uk-UA");
        }
        protected void Application_Start()
        {
            RegisterRoutes(RouteTable.Routes);
            //ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory());
        }
        protected void Application_Error()
        {
        }
    }
}